﻿import request from '@/utils/request'

export function getListPaged(params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: '/api/authserver/organization-units',
    method: 'get',
    params
  })
}

export function getList(params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: '/api/authserver/organization-units/all',
    method: 'get',
    params
  })
}

export function get(id) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}`,
    method: 'get'
  })
}

export function getChildren(params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: '/api/authserver/organization-units',
    method: 'get',
    params
  })
}

export function getRoot() {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: '/api/authserver/organization-units/root-node',
    method: 'get'
  })
}

export function getLastChild(parentId) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/last-children?parentId=${parentId}`,
    method: 'get'
  })
}

export function getRoleNames(id) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/role-names`,
    method: 'get'
  })
}

export function getUnaddedRoles(id, params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/unadded-roles`,
    method: 'get',
    params
  })
}

export function getRoles(id, params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/roles`,
    method: 'get',
    params
  })
}

export function getUnaddedUsers(id, params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/unadded-users`,
    method: 'get',
    params
  })
}

export function getUsers(id, params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/users`,
    method: 'get',
    params
  })
}

export function addUsers(id, data) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/users`,
    method: 'post',
    data
  })
}

export function addRoles(id, data) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/roles`,
    method: 'post',
    data
  })
}

export function move(id, params) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}/move`,
    method: 'put',
    params
  })
}

export function create(data) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: '/api/authserver/organization-units',
    method: 'post',
    data
  })
}

export function update(id, data) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units/${id}`,
    method: 'put',
    data
  })
}

export function remove(id) {
  return request({
    baseURL: process.env.VUE_APP_AUTH,
    url: `/api/authserver/organization-units?id=${id}`,
    method: 'delete'
  })
}
